home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
DDJMAG
/
DDJ9110.ZIP
/
STRING.ZIP
/
STRIINS2.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-30
|
714b
|
32 lines
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <string.hpp>
String &String::insert(int pos, const char *s, int count)
{
int sl = count? count: strlen(s);
if (!sl)
return *this;
if (pos > length()) { // pos == length() is concatenate
errno = ERANGE;
return *this;
}
int n = length()+sl;
srep *p = new(n) srep(n);
if (!p) {
errno = ENOMEM;
return *this;
}
memmove(p->body,body(),pos);
memmove(p->body+pos, s, sl);
memmove(p->body+pos+sl, body()+pos, length()-pos);
if (rp) {
if (--rp->refs < 1)
delete rp;
}
rp = p;
rp->refs++;
return *this;
}